package cn.antho.shop.service.impl;

import cn.antho.shop.domain.Systemdictionarydetail;
import cn.antho.shop.domain.Systemdictionarytype;
import cn.antho.shop.mapper.SystemdictionarydetailMapper;
import cn.antho.shop.mapper.SystemdictionarytypeMapper;
import cn.antho.shop.result.JsonResult;
import cn.antho.shop.service.ISystemdictionarydetailService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author director
 * @since 2022-11-18
 */
@Service
public class SystemdictionarydetailServiceImpl extends ServiceImpl<SystemdictionarydetailMapper, Systemdictionarydetail> implements ISystemdictionarydetailService {

    @Autowired
    SystemdictionarytypeMapper systemdictionarytypeMapper;

    @Override
    public boolean insert(Systemdictionarydetail entity) {
        Systemdictionarytype type = systemdictionarytypeMapper.findByName(entity.getType());
        if (null == type) {
            Systemdictionarytype systemdictionarytype = new Systemdictionarytype();
            systemdictionarytype.setName(entity.getType());
            Long id = Long.valueOf(systemdictionarytypeMapper.insert(systemdictionarytype));
            Systemdictionarydetail detail = new Systemdictionarydetail();
            detail.setName(entity.getName());
            detail.setTypesId(id);
            return super.insert(detail);
        }
        Systemdictionarydetail detail = new Systemdictionarydetail();
        detail.setName(entity.getName());
        detail.setTypesId(type.getId());
        return super.insert(detail);
    }
}
